<?php  
class BrandController extends AuthController{
	private $db;
	private $bid;
	private $brand;
	public function __init(){
		$this->db=K('Brand');
		$this->bid=Q('brand_id',0,'intval');
		$this->brand=S('brand');
	}
	public function index(){
		$this->assign('brand',$this->db->order('brand_order asc')->all());
		$this->display();
	}
	// 添加品牌
	public function add(){
		if (IS_POST) {
			if ($this->db->addBrand()) {
				$this->success('添加成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$this->display();
		}
	}
	// 编辑品牌
	public function edit(){
		if (IS_POST) {
			if ($this->db->editBrand()) {
				$this->success('修改成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$brand=$this->db->where("brand_id=".$this->bid)->find();
			$brand['brand_logo']=array(
				array('path'=>$brand['brand_logo'])
				);
			$this->assign('brand',$brand);
			$this->display();
		}
	}
	// 删除品牌及其图片
	public function del(){
		if ($this->db->delBrand()) {
			$this->success('删除成功','index');
		}else{
			$this->error($this->db->error);
		}
	}
	//更新缓存
	public function update(){
		if ($this->db->updateCache()) {
			$this->success();
		}else{
			$this->error($this->db->error);
		}
	}
	//异步更改排序
	public function _order(){
		if ($this->db->updateOrder()) {
			echo json_encode(array('state' => 1, 'message' => ' 修改成功 ','timeout'=>0.1));exit;
		}else{
			echo json_encode(array('state' => 0, 'message' => ' 修改失败 ','timeout'=>1));exit;
		}
	}
}
?>